<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
      /* 
       Object.defineProperty()
      在一个对象上定义一个新属性（可以更改这个对象上现有的属性），将这个对象返回
      */
     let obj = {
         firstName:'a',
         lastName:'b'
     }
     obj.fullName = 'a-b';
    //  需求：fullName = firstName + ‘-’ + lastName  a b  a-b
    // 当fullName更改 firstName lastName  aaa-bbb    aaa  bbb

    Object.defineProperty(obj,'fullName',{
        get(){
            return this.firstName + '-' + this.lastName;
        },
        set(value){
            console.log(value);
            let arr = value.split('-');
            this.firstName = arr[0];
            this.lastName =arr[1];
        }
    })
    console.log(obj);
    // set数据劫持
    obj.fullName = 'fehwf-fewrg';


    </script>
</body>
</html>